package com.lwphk.easydocs.core;

import java.lang.reflect.Method;
import java.lang.reflect.Parameter;
import java.util.List;
import java.util.Map;
import java.util.Set;

import com.lwphk.easydocs.annotations.DocNil;
import com.lwphk.easydocs.core.parameter.parse.ArrayParameterHandler;
import com.lwphk.easydocs.core.parameter.parse.EnumParameterHandler;
import com.lwphk.easydocs.core.parameter.parse.ListParameterHandler;
import com.lwphk.easydocs.core.parameter.parse.MapParameterHandler;
import com.lwphk.easydocs.core.parameter.parse.OtherParameterHandler;
import com.lwphk.easydocs.core.parameter.parse.PrimitiveParameterHandler;
import com.lwphk.easydocs.core.parameter.parse.SetParameterHandler;
import com.lwphk.easydocs.core.parameter.parse.UploadParameterHandler;
import com.lwphk.easydocs.core.vo.DocsBasicInfo;
import com.lwphk.easydocs.core.vo.MethodInfo;
import com.lwphk.easydocs.util.ClassTypeUtil;

public class ParseParameterAdapter {

	public void parseParameter(Method method, MethodInfo mi) {

		ParameterParseAbstract handler = null;
		// 方法请求参数
		Parameter[] ps = method.getParameters();
		for (Parameter parameter : ps) {
			
			
			
			
			
			
			Class<?> parameterType = parameter.getType();
			if (parameter.getAnnotation(DocNil.class) != null)
				continue;
			if (DocsBasicInfo.ExcludeParamSet.contains(parameterType.getName()))
				continue;
			if(ClassTypeUtil.isPrimitive(parameterType)) {
				handler = new PrimitiveParameterHandler();
			}else if(ClassTypeUtil.isUpload(parameter)) {
				
				handler = new UploadParameterHandler();
			}
			else if (parameterType.isArray()) {
				handler = new ArrayParameterHandler();
		       
		    } else if (List.class.isAssignableFrom(parameterType)) {
		    	handler = new ListParameterHandler();
		     
		    } else if (Set.class.isAssignableFrom(parameterType)) {
		    	handler = new SetParameterHandler();
		        
		    } else if (Map.class.isAssignableFrom(parameterType)) {
		    	handler = new MapParameterHandler();
		     
		       
		    } else if (Enum.class.isAssignableFrom(parameterType)) {
		    	handler = new EnumParameterHandler();
		    } else {
		    	handler = new ListParameterHandler();
		    }
			
			try {
				handler.parse(parameter, mi);
			} catch (Exception e) {
				e.printStackTrace();
			}
			
			
		}
	}
	

	
	
	



	
	
	
	
	

	

	
}
